package Experimentos;
import esc2.*;
import aima.search.framework.Problem;
import aima.search.framework.Search;
import aima.search.framework.SearchAgent;
import aima.search.informed.HillClimbingSearch;
import aima.search.informed.SimulatedAnnealingSearch;

import comun.GeneradorProblemas;

public class Main9 {

	public static void main(String [] args){

		//numero de parametros a probar
		int num_params = 7;
		//repeticiones para un mismo experimento
		int num_reps = 20;
		//parametros en Simulated Annhealing
		int par1[] = {10,10,10,10,10,20,20,20,20,20,30,30,30,30,30,300,3000,10000,10000,10000};
		int par2[] = {1000,5000,10000,10000,10000,1000,5000,10000,10000,10000,1000,5000,10000,10000,10000,50000,500000,1000,500000,1000000};
		int par3[] = {5,5,5,500,500,5,5,5,500,500,5,5,5,500,500,50,100,50,500,1};
		double par4[] = {0.01,0.01,0.01,0.01,0.001,0.01,0.01,0.01,0.01,0.001,0.01,0.01,0.01,0.01,0.001,0.01,0.1,0.01,0.00001,0.1};
		long tiempoIni = 0;
		long tiempoFin = 0;
		double media1 = 0;
		double media2 = 0;
		double media3 = 0;
		double media4 = 0;
		//guardamos resultados para hacer medias
		double result[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
		
		//user Simulated Annhealing ?
		boolean SimAnn = false;
		
		// Estrategia generacion inicial : 0-> Random 1-> Mejor tiempo
		int init = 0;
		
		// Importancia de la StDev en el heuristico
		double k = 0.25;
		
		
		GeneradorProblemas prob = new GeneradorProblemas();
		
		//para cada parametroa a probar
		for (int i = 0; i < num_params; ++i) {
			// para cada repeticion
			try {
			prob.cambioParametros(100+(i*100), 5,5,3);
			for (int j = 0; j< num_reps; ++j) { 
				
				
					tiempoIni = System.currentTimeMillis();
					//Genera el estado inicial
					
					Estado caso1 = new Estado(prob.getPeticiones(), prob.getServidores(), prob.getNumServidores());
					caso1.generarEstadoInicialMenorTiempo();

					//Crea y resuelve el problema
					Problem problema = new Problem(caso1, new FuncionSuccesores(SimAnn), new EsEstadoFinal() , new Heuristico());

					Search algoritmo;
					if (SimAnn == true ) algoritmo = new SimulatedAnnealingSearch(
							par1[i], 
							par2[i], 
							par3[i], 
							par4[i]);
					else algoritmo = new HillClimbingSearch();
					SearchAgent agent = new SearchAgent(problema, algoritmo);

					Estado resultado = (Estado) algoritmo.getGoalState();
					
					//Guardamos resultados si procede
					//...
					
					tiempoFin = System.currentTimeMillis();
					media1 += resultado.getTiempoTotal();
					media2 += resultado.getSinAsignar();
					media3 += resultado.getAllPetition();
					media4 += (tiempoFin-tiempoIni);
					
					
				

			}
			} catch (Exception e) {
				e.printStackTrace();
			} 
			System.out.println("RESULTADOS");
			System.out.println("Tiempo Total final: 		" + (media1/num_reps));
			System.out.println("Numero de peticiones sin asignar: " + (media2/num_reps));
			System.out.println("Numero de peticiones total: " + (media3/num_reps));
			System.out.println("Tiempo para hallar la solucion: " + (media4/num_reps));
			System.out.println("");
			
			media1 =0;
			media2 =0;
			media3 =0;
			media4 =0;

		}
	}


}
